//
//  SingerController.m
//  Coco_Music
//
//  Created by dlios on 15-6-25.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SingerController.h"

@interface SingerController ()

@end

@implementation SingerController
-(void)dealloc
{
    [_singD release];
 
    [_SingName release];

    [_myTableView release];
    [_myArray release];


  
    [super dealloc];
    
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.myTableView reloadData];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor= [UIColor whiteColor];
    
    
    self.navigationItem.title = self.SingName;
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithTitle:@"搜索" style:UIBarButtonItemStyleDone target:self action:@selector(rightBarButtonItem:)];
    
    
    self.myTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStylePlain];
    self.myTableView.backgroundColor =[UIColor whiteColor];
    
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.delegate =self;
    self.myTableView.dataSource =self;
    [self.view addSubview:self.myTableView];
  
    
    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"正在加载,请稍后";
    [self.HUD show:YES];
    
    [self.myTableView.footer endRefreshing];
    [self.myTableView.header endRefreshing];
    [self.myTableView.header beginRefreshing];
    [self.myTableView.footer beginRefreshing];
 
   
}


-(void)rightBarButtonItem:(UIBarButtonItem *)myBarItem
{
    SearchViewController *searchVC =[[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVC animated:YES];
}

#define SongConnect @"http://api.dongting.com/song/singer/%ld/songs?"
#define SongConnect1 @"page=1&size=50&app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"
-(void)setSongID:(NSInteger)SongID
{
    NSString *url =[NSString stringWithFormat:SongConnect,(long)SongID];
 
    NSString *url1 =[NSString stringWithFormat:url,SongConnect1];
    [AFN_block NSString:url1 Blokc:^(id request) {
        NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary:request];
     //   NSLog(@"单曲详情 %@",dic);
        self.myArray =[NSMutableArray array];
        NSMutableArray *dataArray =[dic objectForKey:@"data"];
        for (NSMutableDictionary *myDic in dataArray) {
            single *mySingle =[[single alloc]init];
            mySingle.song_name =[myDic objectForKey:@"name"];
            mySingle.singer_name =[myDic objectForKey:@"singerName"];
            mySingle.favorites =[[myDic objectForKey:@"favorites"]integerValue];
            mySingle.audition_list =[myDic objectForKey:@"auditionList"];
            mySingle.album_name =[myDic objectForKey:@"albumName"];
            for (NSMutableDictionary *auditionDic in mySingle.audition_list ){
                mySingle.duration =[auditionDic objectForKey:@"duration"];
            }
            [self.myArray addObject:mySingle];
            [mySingle release];
           
            }
        [self.myTableView reloadData];
        [self.HUD hide:YES];
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.myArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier=@"cell";
    SongTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell =[[SongTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.mySingle =[self.myArray objectAtIndex:indexPath.row];
    cell.numberLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
        
    }];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
    PlayingViewController *playVC = [PlayingViewController shareHandleController];
    playVC.array = self.myArray;
    playVC.indexPath = indexPath.row;
    UINavigationController *naPlayVC = [[UINavigationController alloc]initWithRootViewController:playVC];
    [self presentViewController:naPlayVC animated:YES completion:^{
        
        
    }];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ([UIScreen mainScreen].bounds.size.height+10)/8;;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
